﻿<%@ Page Language="C#" MasterPageFile="~/Manager.master" AutoEventWireup="true" CodeFile="AddProduct.aspx.cs"
    Inherits="Manager_Product_AddProduct" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script src="<%= ResolveClientUrl("~/")%>Pub/ckeditor/ckeditor.js" type="text/javascript"></script>

    <div>
        <table cellpadding="3" cellspacing="0" border="0" width="100%">
            <tr>
                <td colspan="3" class="BackgroundItem" align="center">
                    <table width="100%" cellpadding="3" cellspacing="0" border="1" class="tbl_Comon-Search">
                        <tr>
                            <td align="left" colspan="7">
                                <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="GrpAdd"
                                    ShowMessageBox="True" ShowSummary="False" />
                            </td>
                        </tr>
                        <tr>
                            <td class="td_Title" align="left" style="width: 143px">
                                Tên sản phẩm&nbsp;
                            </td>
                            <td align="left" class="td_Control" nowrap="nowrap" colspan="6" style="white-space: nowrap;">
                                <asp:TextBox ID="txtTenSP" runat="server" ValidationGroup="GrpAdd" Width="70%" CssClass="txt_Product"
                                    onblur="fnCheckPD(this.value)"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                                        runat="server" ControlToValidate="txtTenSP" ErrorMessage="Nhập vào tên sản phẩm"
                                        ValidationGroup="GrpAdd">*</asp:RequiredFieldValidator>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator51" runat="server" ControlToValidate="hidPD"
                                    ErrorMessage="Tên sản phẩm này đã tồn tại" InitialValue="1" ValidationGroup="GrpAdd"
                                    CssClass="valid_common"> &nbsp;</asp:RequiredFieldValidator>&nbsp;
                                <img src="../../Images/Icon/spinner.gif" border="0" id="imgStatePD" style="visibility: hidden" />
                                <asp:TextBox ID="hidPD" runat="server" CssClass="cssHidden" Text="0" Width="0px"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator52" runat="server" ControlToValidate="hidPD"
                                    ErrorMessage="Đang xử lý..." ValidationGroup="GrpAdd" CssClass="valid_common">Đang xử lý...</asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td class="td_Title" align="left" style="width: 143px">
                                Chủ đề&nbsp;
                            </td>
                            <td align="left" class="td_Control" style="width: 330px">
                                <asp:DropDownList ID="ddlChuDe" runat="server" CssClass="cssDropdownlist" AutoPostBack="True"
                                    OnSelectedIndexChanged="ddlChuDe_SelectedIndexChanged1">
                                </asp:DropDownList></td>
                            <td align="left" class="td_Title" style="width: 111px">
                                <asp:Label ID="Label1" runat="server" Text="Thể loại"></asp:Label></td>
                            <td align="left" class="td_Control" colspan="4" style="white-space: nowrap;">
                                <asp:DropDownList ID="ddlTheLoai" runat="server" CssClass="cssDropdownlist" AutoPostBack="True"
                                    OnSelectedIndexChanged="ddlTheLoai_SelectedIndexChanged">
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="ddlTheLoai"
                                    ErrorMessage="Chọn thể loại" InitialValue="0" ValidationGroup="GrpAdd">*</asp:RequiredFieldValidator></td>
                        </tr>
                        <tr>
                            <td align="left" class="td_Title" style="width: 143px">
                                Hot!</td>
                            <td align="left" class="td_Control" style="width: 330px">
                                <asp:CheckBox ID="chkHot" runat="server" Text="Hot !" ForeColor="Red" /></td>
                            <td align="left" class="td_Title" nowrap style="background-color: #eaeaea; display: none;">
                                Giá gốc</td>
                            <td align="left" class="td_Title" style="width: 330px">
                                Đơn vị tính</td>
                            <td align="left" class="td_Control" style="width: 330px">
                                <asp:DropDownList ID="ddlDonviTinh" runat="server" CssClass="cssDropdownlist">
                                    <asp:ListItem Selected="True">C&#225;i</asp:ListItem>
                                    <asp:ListItem>Sợi</asp:ListItem>
                                    <asp:ListItem>Cặp</asp:ListItem>
                                    <asp:ListItem>Film</asp:ListItem>
                                    <asp:ListItem>Bộ</asp:ListItem>
                                    <asp:ListItem>M&#233;t</asp:ListItem>
                                </asp:DropDownList></td>
                        </tr>
                        <tr>
                            <td class="td_Title" align="left" style="width: 143px">
                                <asp:Label ID="Label4" runat="server" Text="Hạn bảo hành"></asp:Label></td>
                            <td align="left" class="td_Control" style="width: 330px">
                                &nbsp;<asp:TextBox ID="txtHanBaoHanh" runat="server" ValidationGroup="GrpAdd" Width="50%"
                                    CssClass="txt_Product"></asp:TextBox>
                                <asp:Label ID="Label5" runat="server" Text="Tháng" ForeColor="Red"></asp:Label></td>
                            <td align="left" class="td_Title" style="width: 111px">
                                <asp:Label ID="Label3" runat="server" Text="Đơn giá  "></asp:Label><br />
                                <asp:CheckBox ID="chkStatus" runat="server" ToolTip="Hết hàng" onclick="fnCheckOutOf()"
                                    Font-Size="8pt" ForeColor="Red" Text="Hết_hàng" /></td>
                            <td align="left" class="td_Control" colspan="4" style="white-space: nowrap;">
                                <asp:TextBox ID="txtDonGia" runat="server" ValidationGroup="GrpAdd" Width="50%" CssClass="txt_Product"
                                    Text="0" onkeyup="fnDisplayTextMoney(this)"></asp:TextBox>&nbsp;<asp:DropDownList
                                        ID="ddlRate" runat="server" CssClass="cssDropdownlist" ForeColor="Purple">
                                    </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtDonGia"
                                    ErrorMessage="Yêu cầu nhập vào đơn giá" ValidationGroup="GrpAdd">*</asp:RequiredFieldValidator></td>
                        </tr>
                        <tr>
                            <td align="left" class="td_Title" style="width: 143px">
                                <asp:Label ID="Label2" runat="server" Text="Hình minh họa"></asp:Label></td>
                            <td align="left" class="td_Control" style="width: 330px">
                                &nbsp;<table border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td>
                                            <asp:FileUpload ID="FileU_HinhMinhHoa" runat="server" CssClass="txt_Product" />
                                        </td>
                                        <td>
                                            <img id="imgShowImage" runat="server" height="20" width="20" src="../../Images/Icon/show_image.png"
                                                visible="false" style="cursor: pointer" onmouseover="OpenPopUpTooltip(this)"
                                                onmouseout="HidePopUpTooltip()" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td align="left" class="td_Title" style="width: 111px">
                                <asp:CheckBox ID="chkSaleOf" runat="server" onclick="fnCheckSaleOf()" />Khuyến mãi</td>
                            <td align="left" class="td_Control" colspan="4" style="white-space: nowrap">
                                <asp:TextBox ID="txtSaleOf" runat="server" CssClass="txt_Product" ValidationGroup="GrpAdd"
                                    onkeyup="fnDisplayTextMoney(this)" Width="50%" BackColor="#EAEAEA">0</asp:TextBox>
                                <asp:DropDownList ID="ddlRateSaleOf" runat="server" CssClass="cssDropdownlist" ForeColor="Purple"
                                    Enabled="false">
                                </asp:DropDownList></td>
                        </tr>
                        <tr>
                            <td align="left" class="td_Title" style="width: 143px">
                                <asp:Label ID="Label6" runat="server" Text="Dung lượng"></asp:Label></td>
                            <td align="left" class="td_Control" style="width: 330px">
                                <asp:TextBox ID="txtCapacity" runat="server" CssClass="txt_Product" ValidationGroup="GrpAdd"
                                    Width="30%"></asp:TextBox>
                                <asp:Label ID="Label7" runat="server" ForeColor="Red" Text="GB"></asp:Label></td>
                            <td align="left" class="td_Title" style="width: 111px">
                            </td>
                            <td align="left" class="td_Control" colspan="4" style="white-space: nowrap">
                            </td>
                        </tr>
                        <tr>
                            <td align="left" class="td_Control" colspan="7" style="background-color: azure" valign="middle">
                                <asp:Label ID="lblEmpty" runat="server" Text="Chưa có thuộc tính" Visible="False"
                                    Font-Bold="True" Font-Names="Tahoma" Font-Size="10pt" ForeColor="Red"></asp:Label><asp:GridView
                                        ID="grv_PropertiesDetail" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                                        BorderColor="#407DB3" CellPadding="2" Width="100%" OnRowDataBound="grv_PropertiesDetail_RowDataBound">
                                        <Columns>
                                            <asp:TemplateField>
                                                <HeaderTemplate>
                                                    Tên thuộc tính
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="lblMaTT" runat="server" Text='<%# Eval("PrtID") %>' Visible="false"></asp:Label>
                                                    <asp:Label ID="lblTenTT" runat="server" Text='<%# Eval("PrtNm") %>'></asp:Label>
                                                </ItemTemplate>
                                                <ItemStyle CssClass="cssBorderGrv" HorizontalAlign="Left" Wrap="False" />
                                                <HeaderStyle CssClass="cssBorderGrv" HorizontalAlign="Left" Wrap="False" />
                                            </asp:TemplateField>
                                            <asp:TemplateField>
                                                <HeaderTemplate>
                                                    Danh sách thuộc tính
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    <asp:TextBox ID="txtTenCTTTSP" runat="server" Text='' Width="95%" CssClass="txt_Product"></asp:TextBox>
                                                </ItemTemplate>
                                                <ItemStyle CssClass="cssBorderGrv" HorizontalAlign="Left" Width="85%" />
                                                <HeaderStyle CssClass="cssBorderGrv" HorizontalAlign="Left" />
                                            </asp:TemplateField>
                                        </Columns>
                                        <RowStyle CssClass="gvRowStyle" />
                                        <AlternatingRowStyle CssClass="gvAlternatingRowStyle" />
                                        <HeaderStyle CssClass="gvHeader" />
                                    </asp:GridView>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="7" style="border-bottom-color: #407db3; border-top-color: #407db3;
                                background-color: lightcyan; border-right-color: #407db3">
                                &nbsp;
                                <textarea name="FCKeditor1" id="FCKeditor1" runat="server"  style="height:300px;width:95%;"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" class="td_Control" colspan="7">
                                &nbsp;</td>
                        </tr>
                        <tr>
                            <td align="left" colspan="7">
                                &nbsp;</td>
                        </tr>
                        <tr>
                            <td style="width: 143px" class="cssManage_Product" align="left">
                            </td>
                            <td align="left" colspan="6">
                                <asp:Button ID="btnUpdate" runat="server" Text="Bảo lưu" CssClass="cssButton" ValidationGroup="GrpAdd"
                                    Width="80px" OnClick="btnUpdate_Click" />
                                <asp:Button ID="btnBack" runat="server" Text="Quay lại" CssClass="cssButton" OnClick="btnBack_Click"
                                    Width="80px" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <br />
        <input type="hidden" id="hidDescID" name="hidDescID" />
        <input type="hidden" id="hImg" name="hImg" runat="server" value="" />
        <input type="hidden" id="hidUPdProperties" runat="server" />
        <input id="hidMaSP" runat="server" type="hidden" />
        <br />
        <div style="margin-left: 200px">
            &nbsp;
        </div>
    </div>
    <div class='product_popup' id="divTooltip" onmouseover="OpenDivPopUpTooltip()" onmouseout="HidePopUpTooltip(this)"
        style="position: absolute">
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td colspan="3" nowrap="nowrap" rowspan="2" class="product_detail_popup" id="tdProductDetail"
                    style="text-align: center">
                    <img runat="server" id="imgURL" onclick="HidePopUpTooltip()" />
                </td>
            </tr>
            <tr>
            </tr>
        </table>
    </div>

    <script language="javascript" type="text/javascript">
    CKEDITOR.replace(
    document.getElementById("<%= FCKeditor1.ClientID%>")
    );        

    
    function fnDisplayTextMoney(obj)
        {
            obj.value=FormatMoney(obj.value.ReplaceAll(",",""))   ; 
        }
     function fnCheckOutOf()
     {
        var obj=document.getElementById("<%= chkStatus.ClientID%>");
        if(obj.checked==true)
        {    
             document.getElementById("<%= chkSaleOf.ClientID%>").style.visibility="hidden";
            document.getElementById("<%= txtDonGia.ClientID%>").onkeypress=function()
            {
                return false; 
            }  
            document.getElementById("<%= txtDonGia.ClientID%>").style.backgroundColor="#eaeaea";
            document.getElementById("<%= ddlRate.ClientID%>").disabled="disabled";
           
            var obj=document.getElementById("<%= chkSaleOf.ClientID%>");
            obj.checked=false;   
           fnCheckSaleOf(); 

        }
        else
        {
             document.getElementById("<%= chkSaleOf.ClientID%>").style.visibility="visible";
            document.getElementById("<%= txtDonGia.ClientID%>").onkeypress=function()
            {
                return true; 
            }  
           
            
            document.getElementById("<%= txtDonGia.ClientID%>").style.backgroundColor="white";
            document.getElementById("<%= ddlRate.ClientID%>").removeAttribute("disabled");
            
           
        }
     }
     
     function fnCheckSaleOf()
     {
        var obj=document.getElementById("<%= chkSaleOf.ClientID%>");
        if(obj.checked==true)
        {
            document.getElementById("<%= txtSaleOf.ClientID%>").removeAttribute("onkeypress");
            document.getElementById("<%= txtSaleOf.ClientID%>").style.backgroundColor="white";
            document.getElementById("<%= ddlRateSaleOf.ClientID%>").removeAttribute("disabled");
           
          document.getElementById("<%= txtSaleOf.ClientID%>").onkeypress=function()
            {
                return true; 
            }    
            
           /* document.getElementById("<%= txtDonGia.ClientID%>").readOnly="readOnly";
            document.getElementById("<%= txtDonGia.ClientID%>").style.backgroundColor="#eaeaea";
            document.getElementById("<%= ddlRate.ClientID%>").disabled="disabled";*/

        }
        else
        {
            document.getElementById("<%= txtSaleOf.ClientID%>").onkeypress=function()
            {
                return false; 
            }  
            document.getElementById("<%= txtSaleOf.ClientID%>").style.backgroundColor="#eaeaea";
            document.getElementById("<%= ddlRateSaleOf.ClientID%>").disabled="disabled";
            
           /* document.getElementById("<%= txtDonGia.ClientID%>").readOnly=false;
            document.getElementById("<%= txtDonGia.ClientID%>").style.backgroundColor="white";
            document.getElementById("<%= ddlRate.ClientID%>").disabled=false;*/
            
           
        }
     }
     
     //====================================================================
     
     function OpenPopUpTooltip(obj)
     {  
       obj.style.cursor="pointer";
 
       
        var divTooltip=document.getElementById("divTooltip");
        divTooltip.style.visibility="visible" ;
  
        var sleft=ObjectPosition(obj)[0];       
        var stop=ObjectPosition(obj)[1]-(divTooltip.clientHeight/2);    
     
        divTooltip.style.left = sleft + 'px';
        divTooltip.style.top =  stop+ 'px'; 
    }
    function ObjectPosition(obj) 
    {
          var curleft = 0;
          var curtop = 0;
          if (obj.offsetParent) {
                do {
                      curleft += obj.offsetLeft;
                      curtop += obj.offsetTop;
                } while (obj = obj.offsetParent);
          }
          return [curleft,curtop];
	}
	
	
	 function HidePopUpTooltip(obj)
     { 
             var divTooltip=document.getElementById("divTooltip");
             divTooltip.style.visibility="hidden";

             
     }
     
     function OpenDivPopUpTooltip()
     { 
             var divTooltip=document.getElementById("divTooltip");
             divTooltip.style.visibility="visible"
     }
	
	
    function fnGetcategoryID(IDTopic)
    {      
        Manager_Product_AddProduct.AjaxGetCatByTopicID(IDTopic,CallBackGetcategoryID)
    }
    function CallBackGetcategoryID(res)
    {
        if(res!=null)
        {
            var ds=res.value;
            if(ds!=null && typeof(ds)=="object" && ds.Tables!=null)
			{	
			    var ddlTheLoai=document.getElementById("<%= ddlTheLoai.ClientID %>");
				ddlTheLoai.options.length=0;
				var len=ds.Tables[0].Rows.length;	
				var CatID="";
				var CatNm="";
				ddlTheLoai.options[0]=new Option("--Chọn thể loại--","0");
				for(var i=0;i<len;i++)
				{	
					CatNm=ds.Tables[0].Rows[i].CatName;
					CatID=ds.Tables[0].Rows[i].CatID;						
					ddlTheLoai.options[i+1]=new Option(CatNm,CatID);
				}	
			}	
        }
    }
    function fnHideImgPD()
    {
        var imgStatePD=document.getElementById("imgStatePD");
        imgStatePD.style.visibility="hidden"; 
    }
    function fnCheckPD(sValue)
    {     
        var PDID='<%= Request.QueryString["PDID"] %>';  
        if(trim(sValue)=="") {
        return;}
        Manager_Product_AddProduct.AjaxCheckPD(sValue,PDID,CallBackPD);  

     
    }
    function CallBackPD(res)
    {
        if(res!=null)
        {
            var flag=res.value;
            if(flag!=null && flag!="")
			{	
			    var imgStatePD=document.getElementById("imgStatePD");

			    var hidPD=document.getElementById("<%= hidPD.ClientID %>");
			    hidPD.value="aaa"; //Tranh su kien dang su ly
		
			    if(flag=="yes")
			    {   imgStatePD.style.visibility="visible";
			        imgStatePD.src="../../Images/Icon/cmdDelete.gif";
			        imgStatePD.alt="Sản phẩm này đã tồn tại";			        
			        hidPD.value="0";
			       
			    }		
			    else
			    {
			           imgStatePD.style.visibility="hidden";
			    }	    
			}	
        }
    }
     function trim(str)
     {
        return str.replace(/^\s+/, '').replace(/.*\s+$/, '');
     }
    </script>

</asp:Content>
